local xisheng = fk.CreateSkill {
  name = "th_xisheng",
  tags = { Skill.Compulsory },
}

xisheng:addEffect(fk.TurnEnd, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(xisheng.name) and (player:isKongcheng() or table.every(room:getOtherPlayers(player, false), function(p) return p:getHandcardNum() > player:getHandcardNum() end)) then
      local ids = {}
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              if room:getCardArea(info.cardId) == Card.DiscardPile and move.moveReason ~= fk.ReasonUse then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end, Player.HistoryTurn)
      if #ids > 0 then
        event:setCostData(self, { cards = ids })
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = event:getCostData(self).cards
    if #ids > 1 then
      local cards, _ = room:askToChooseCardsAndChoice(player, {
        cards = ids,
        choices = {"OK"},
        skill_name = xisheng.name,
        prompt = "#th_xisheng-choose"
      })
      if #cards > 0 then
        ids = cards
      end
    end
    room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, xisheng.name)
  end,
})

Fk:loadTranslationTable{
  ["th_xisheng"] = "希声",
  [":th_xisheng"] = "锁定技，每回合结束时，若你没有手牌或手牌唯一最少，你获得本回合不因使用进入弃牌堆的一张牌。",

  ["#th_xisheng-choose"] = "希声：你须获得其中一张牌",
}

return xisheng